﻿using System;
using System.Text.RegularExpressions;

namespace KWatkins.FluentMoqBuilder.Argument
{
	internal sealed class StringValidation : ArgumentValidation<string>,
		IString, IStringNotNull, IStringNotEmpty
	{
		internal StringValidation(string argument, string parameterName)
			: base(argument, parameterName)
		{
		}

		#region IStringRoot Members
		IStringNotNull IString.IsNotNull()
		{
			if (Argument == null)
			{
				throw new ArgumentNullException(ParameterName);
			}
			return this;
		}
		#endregion
		#region IStringNotNull Members
		IStringNotEmpty IStringNotNull.IsNotEmpty()
		{
			if (Argument.Length == 0)
			{
				throw new ArgumentException("Value cannot be empty.", ParameterName);
			}
			return this;
		}
		#endregion
		#region IStringNotEmpty Members
		public IStringNotEmpty IsMatch(Regex regex)
		{
			Validate.Argument(regex, "regex").IsNotNull();

			if (!regex.IsMatch(Argument))
			{
				throw new ArgumentException("Value is not in the correct format.", ParameterName);
			}

			return this;
		}
		#endregion
	}
}
